package com.hongkou.tvstation.image.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hongkou.tvstation.common.CodeCst;
import com.hongkou.tvstation.common.action.GenericAction;
import com.hongkou.tvstation.common.action.MultiWarning;
import com.hongkou.tvstation.common.utils.DateUtils;
import com.hongkou.tvstation.common.utils.StringUtils;
import com.hongkou.tvstation.image.dao.ImageDao;
import com.hongkou.tvstation.image.data.TImage;
import com.hongkou.tvstation.image.vo.ImageVO;

public class QueryImagesAction extends GenericAction {
	public static final String path = "images/";

	@Override
	public ActionForward process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ImageManagementActionForm imageForm = (ImageManagementActionForm) form;
		ImageVO queryVO = new ImageVO();
		queryVO.setPageNum(Long.valueOf(imageForm.getPageNum()));
		if (!StringUtils.isNullOrEmpty(imageForm.getCategory()))
			queryVO.setCategory(Long.valueOf(imageForm.getCategory()));
		if (!StringUtils.isNullOrEmpty(imageForm.getImageName())) {
			queryVO.setImageName(imageForm.getImageName());
		}
		if (!StringUtils.isNullOrEmpty(imageForm.getImageGroup()))
			queryVO.setImageGroup(Integer.valueOf(imageForm.getImageGroup()));
		if (!StringUtils.isNullOrEmpty(imageForm.getShootingStartTime()))
			queryVO.setShootingStartTime(DateUtils.toDate(imageForm
					.getShootingStartTime()));
		if (!StringUtils.isNullOrEmpty(imageForm.getShootingEndTime()))
			queryVO.setShootingEndTime(DateUtils.toDate(imageForm
					.getShootingEndTime()));
		List<TImage> imageList = imageDao.findImages(queryVO);
		request.setAttribute("imageList", imageList);
		request.setAttribute("pageVO", queryVO.getPageVO());
		return mapping.findForward(CodeCst.FORWARD__IMAGE_PAGE);
	}

	@Override
	public MultiWarning processWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		MultiWarning mw = new MultiWarning();
		return null;
	}

	private ImageDao imageDao;

	public ImageDao getImageDao() {
		return imageDao;
	}

	public void setImageDao(ImageDao imageDao) {
		this.imageDao = imageDao;
	}
}
